package com.ruoyi.basedata.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.basebill.domain.WfzSbsjsentry;
import com.ruoyi.basedata.domain.BdMaterial;
import com.ruoyi.basedata.domain.OmsSettlementpriceentry;
import com.ruoyi.basedata.service.IBdMaterialService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.OmsSettlementprice;
import com.ruoyi.basedata.service.IOmsSettlementpriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 结算价格Controller
 *
 * @author ptt
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/settlementCenter/basedata/settlementprice")
public class OmsSettlementpriceController extends BaseController
{
    @Autowired
    private IOmsSettlementpriceService omsSettlementpriceService;

    @Autowired
    private IBdMaterialService bdMaterialService;

    /**
     * 查询结算价格列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsSettlementprice omsSettlementprice)
    {
        startPage();
        //查询10条符合条件的单据头数据
        List<Long> ids = omsSettlementpriceService.selectOmsSettlementpriceIdList(omsSettlementprice);
        if (StringUtils.isEmpty(ids)){
            return getDataTable(new ArrayList<>());
        }
        TableDataInfo dataTable = getDataTable(ids);
        List<OmsSettlementprice> list = omsSettlementpriceService.selectOmsSettlementpriceAndEntryList(ids);
        dataTable.setRows(list);
        return dataTable;
    }

    /**
     * 导出结算价格列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:export')")
    @Log(title = "结算价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsSettlementprice omsSettlementprice)
    {
        List<OmsSettlementprice> list = omsSettlementpriceService.selectOmsSettlementpriceList(omsSettlementprice);
        ExcelUtil<OmsSettlementprice> util = new ExcelUtil<OmsSettlementprice>(OmsSettlementprice.class);
        util.exportExcel(response, list, "结算价格数据");
    }

    /**
     * 下载模板
     * @param response
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<OmsSettlementpriceentry> util = new ExcelUtil<>(OmsSettlementpriceentry.class);
        util.importTemplateExcel(response,"结算价分录");
    }


    /**
     * 获取结算价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(omsSettlementpriceService.selectOmsSettlementpriceById(id));
    }

    /**
     * 新增结算价格
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:add')")
    @Log(title = "结算价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsSettlementprice omsSettlementprice)
    {
        return success(omsSettlementpriceService.insertOmsSettlementprice(omsSettlementprice));
    }

    /**
     * 修改结算价格
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:edit')")
    @Log(title = "结算价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsSettlementprice omsSettlementprice)
    {
        return success(omsSettlementpriceService.updateOmsSettlementprice(omsSettlementprice));
    }

    /**
     * 删除结算价格
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:remove')")
    @Log(title = "结算价格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsSettlementpriceService.deleteOmsSettlementpriceByIds(ids));
    }

    /**
     * 查询物料对象列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:query')")
    @Log(title = "结算价格", businessType = BusinessType.DELETE)
    @GetMapping("/material")
    public AjaxResult queryMaterial()
    {
        List<BdMaterial> bdMaterials = bdMaterialService.selectLikeBdMaterialList();
        return success(bdMaterials);
    }
    /**
     * 查询物料对象
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:settlementprice:query')")
    @Log(title = "结算价格", businessType = BusinessType.DELETE)
    @GetMapping("/material/{Number}")
    public AjaxResult queryMaterialObject(@PathVariable String Number)
    {
        BdMaterial bdMaterials = bdMaterialService.selectBdMaterialByNumber(Number);
        return success(bdMaterials);
    }
}